-
Notifications
You must be signed in to change notification settings - Fork 45
grammar and other edits #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
В контексте примера было не понятно, что такое ADL, дополнил пример
Добавил заметку про Fold expressions
|
Я добавил заметку про Fold Expression, если она имеет место быть, я хотел бы получить картинку с практики, где показывали графики с использовался fold exp и нет, чтобы вставить её в конце для наглядности |
|
Также сделал несколько грамматических исправлений (grammar). И немного изменил пример на странице 16_namespaces_using_adl |
Почистил заметку
Из-за того, что функции объявлены в одном порядке, а используются в другом возникает путаница, что из них считать первым вариантом. Решил чётко разграничить
src/10_libraries.md
Outdated
| } | ||
| ``` | ||
| ```c++ | ||
| // five |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
five.cpp, тогда уж
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/16_namespaces_using_adl.md
Outdated
| ```c++ | ||
| namespace my_lib { | ||
| struct big_integer {}; | ||
| void swap(big_integer&, big_integer&) {// ... //} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
таких комментариев в языке нет, лучше /* и */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/20_perfect_forwarding.md
Outdated
| В **C++17** появилась фича **Fold Expressions**, позволяющая сделать свёртку по элементам пака относительно бинарного оператора. | ||
| Мотивирующий пример: попробуем научиться проверять, есть ли тип (T) в паке. Так как пак в C++ имеет вид lazy array (То есть мы имеем право получить только Head и Tail), очевидна следующая реализация: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
имена типов и других идентификаторов лучше заключать в `
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/20_perfect_forwarding.md
Outdated
| В **C++17** появилась фича **Fold Expressions**, позволяющая сделать свёртку по элементам пака относительно бинарного оператора. | ||
| Мотивирующий пример: попробуем научиться проверять, есть ли тип (T) в паке. Так как пак в C++ имеет вид lazy array (То есть мы имеем право получить только Head и Tail), очевидна следующая реализация: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
часть предложения в скобках не должна начинаться с большой буквы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вроде fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не знаю, является ли "C++26", но если является напишите
src/20_perfect_forwarding.md
Outdated
| В **C++17** появилась фича **Fold Expressions**, позволяющая сделать свёртку по элементам пака относительно бинарного оператора. | ||
| Мотивирующий пример: попробуем научиться проверять, есть ли тип (T) в паке. Так как пак в C++ имеет вид lazy array (То есть мы имеем право получить только Head и Tail), очевидна следующая реализация: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lazy array" это какой-то распространённый в таком контексте термин? я впервые слышу
давай или ссылку, где он применяется, либо не будем его упоминать
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ну здесь имеется в виду lazy sequence, но я лучше это просто уберу
src/20_perfect_forwarding.md
Outdated
| }; | ||
| ``` | ||
|
|
||
| Чем плоха такая реализация? Предположим в паке N элементов, тогда компилятор будет проводить N инстансов шаблона `have_type`. Как можно это пофиксить? Вспомним, что `...` ставится там, где перечисляются элементы. В Fold expressions это и используется. Тогда предыдущий пример можно переписать так: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto про идентификаторы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/20_perfect_forwarding.md
Outdated
| В **C++17** появилась фича **Fold Expressions**, позволяющая сделать свёртку по элементам пака относительно бинарного оператора. | ||
| Мотивирующий пример: попробуем научиться проверять, есть ли тип (T) в паке. Так как пак в C++ имеет вид lazy array (То есть мы имеем право получить только Head и Tail), очевидна следующая реализация: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
перед сложным примером, уходящим в сторону метапрограммирования, полезно показать какой-нибудь более простой и типичный пример свёртки
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавил пример с sum
src/20_perfect_forwarding.md
Outdated
|
|
||
| template <typename Type, typename... Types> | ||
| struct have_type<Type, Types...> { | ||
| static constexpr bool value = std::is_same_v<Type, Types> || ...; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это не скомпилируется по нескольким причинам
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/20_perfect_forwarding.md
Outdated
| Чем это хорошо? | ||
| - Нет рекурсии. | ||
| - Быстрее compile time, потому что меньше инстансов и у компилятора есть возможность делать оптимизации. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
английский ну совсем на ровном месте, давай заменим на "время компиляции"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/20_perfect_forwarding.md
Outdated
| Чем это хорошо? | ||
| - Нет рекурсии. | ||
| - Быстрее compile time, потому что меньше инстансов и у компилятора есть возможность делать оптимизации. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не совсем понял, о каких оптимизациях речь
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я здесь немного ошибся с примером в метапрограммировании (хотя здесь тоже должны быть оптимизации, потому что проиходит свёртка булов). Здесь всё-таки имеются в виду вообще оптимизации fold-ов, даже вне метапроги. Насчёт оптимизаций: я вообще думал, что компилятор умеет делать что-то типо свёртки констант в компайл тайме (Например свернуть sum(1, 2, 3, 4) в return 10), но почему-то когда я начал это на godbolt писать, то оно не воспроизвелось. Есть оптимизация булов https://godbolt.org/z/nbKcof5qf вот тут видно, что компилятор может соптимизировать вывод false после первого встреченного false, конечно он делает нечто подобное и в случае когда вызывается функция two, но он её не инлайнит, поэтому может быть больше джампов по программе например. Да и пример может быть сложнее. +у компилятора есть пространство для векторизации(то есть, допустим сложить несколько чиселок за 1 инструкцию). В общем случае, всё, что сказано выше заключено во фразе "Нет рекурсии", но я считаю важным написать про оптимизации
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я засомневался, что пример с оптимизацией булов действительно подходит, поэтому вот пример когда работает constant folding с делением https://godbolt.org/z/MYqYcnzG6 (с -O2)
No description provided.